package com.itheima.web.controller;

import com.itheima.entity.Region;
import com.itheima.entity.dto.RegionDto;
import com.itheima.entity.vo.PageVo;
import com.itheima.service.NodeService;
import com.itheima.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 区域管理控制层
 *
 * @Author: LiJinLong
 * @Date: 2022-08-17  14:31
 * @Description:
 */
@RestController
@RequestMapping("/api/vm-service/region")
public class RegionController {
    @Autowired
    RegionService regionService;
    @Autowired
    NodeService nodeService;

    /**
     * 区域管理分页查询
     *
     * @param pageIndex
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/search")
    public PageVo<RegionDto> seleByPage(Long pageIndex, Long pageSize, String name) {
        return regionService.SelectPage(pageIndex, pageSize, name);
    }

    /**
     * 新增区域
     *
     * @return
     */
    @PostMapping
    public Boolean add(@RequestBody RegionDto regionDto) {
        regionService.add(regionDto);
        return true;
    }

    /**
     * 修改区域
     */
    @PutMapping("{id}")
    public Boolean updateByid(@PathVariable Long id, @RequestBody Map<String,String>map) {
        Region region = new Region();
        region.setName(map.get("regionName"));
        region.setRemark(map.get("remark"));
        region.setId(id);
        regionService.update(region);
        return true;
    }
    @DeleteMapping("{id}")
    public Boolean delete(@PathVariable Long id){
        return regionService.delete(id);
    }
}
